package com.yuan.base.framework.http;

import android.text.TextUtils;

import com.yuan.base.framework.BaseAppContext;
import com.yuan.base.utils.PreferencesUtils;


/**
 * 基础Url类(子应用使用需继承)
 */
public class BaseUrl {

	private static final String SERVER_ADDRESS = "serverAddress";

	private static String domain = "http://";

	private static String host = "";

	private static String appContext = "";// 调试机器的工程名

	private static String address;

	public static void urlInit(String domain, String host, String appContext) {
		address = getDomain() + getHost() + getAppContext();
		PreferencesUtils.putString(BaseAppContext.getInstance(), SERVER_ADDRESS, address);
	}

	public static void urlInit(String address) {
		BaseUrl.address = address;
		PreferencesUtils.putString(BaseAppContext.getInstance(), SERVER_ADDRESS, address);
	}

	public static void setAppContext(String appContext) {
		BaseUrl.appContext = appContext;
	}

	public static String getAppContext() {
		return appContext;
	}

	public static void setHost(String host) {
		BaseUrl.host = host;
	}

	public static String getHost() {
		return host;
	}

	public static String getDomain() {
		return domain;
	}

	public static void setDomain(String domain) {
		BaseUrl.domain = domain;
	}

	// 返回Http方式的待主机的前缀：http://192.168.143.175:8080/ or http://192.168.143.175:8080/Sales
	public static String getApiHost() {
		if (TextUtils.isEmpty(address)) {
			address = PreferencesUtils.getString(BaseAppContext.getInstance(), SERVER_ADDRESS);
		}
		return address;
	}

	// 获取Url
	public static String getUrl(String interfaceStr) {
		return getApiHost() + interfaceStr;
	}

	/* ===============================系统相关=============================== */
	// 获取app版本信息
	public static String getVersion = "/app/user/getVersion";
	public static String downFile = "/file";

}
